package DAO;/*
@author joker
@create 2022-03-09 15:42
*/

import javabean.totalFee;

import java.util.List;

public class TotalFeeDAO extends BasicDAO<totalFee> {
    //1. 就有BasicDAO的所有方法
    //2. 根据业务需求,可以编写特有的的方法

    /*管理员模块*/
    //1. 当月收入统计 返回所有对象
    public List<totalFee> getAllFee() {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "select * from totalfee";
        return totalFeeDAO.queryMultiply(sql, totalFee.class);
    }

    //2. 更改总收入, 传入新的总收入
    public int changeTotalIncome(int newIncome) {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "update totalfee set totalincome = ? where index1 = 0";
        int num = totalFeeDAO.update(sql, newIncome);
        if (num != 0) {
            System.out.println("总收入更改成功,newIncome = " + newIncome);
        }
        return num;
    }

    //3. 更改退款总金额, 需要传入新的退款总金额
    public int changeRefund(int newrefund) {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "update totalfee set refund = ? where index1 = 0";
        int num = totalFeeDAO.update(sql, newrefund);
        if (num != 0) {
            System.out.println("总收入更改成功,newrefund = " + newrefund);
        }
        return num;
    }

    //4. 更改月卡收入,需要传入新的月卡收入
    public int changeMonthIncome(int newMIncome) {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "update totalfee set monthincome = ? where index1 = 0";
        int num = totalFeeDAO.update(sql, newMIncome);
        if (num != 0) {
            System.out.println("月卡收入更改成功,newMIncome = " + newMIncome);
        }
        return num;
    }

    //5. 更改次卡收入,需要传入新的次卡收入
    public int changeTimeIncome(int newTIncome) {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "update totalfee set Timesincome = ? where index1 = 0";
        int num = totalFeeDAO.update(sql, newTIncome);
        if (num != 0) {
            System.out.println("次卡收入更改成功,newIncome = " + newTIncome);
        }
        return num;
    }

    //6. 获取当前总收入
    public int getTotalFee() {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "select totalincome from totalfee where index1 = 0";
        int TotalFee = (int) totalFeeDAO.queryScalar(sql);
        System.out.println("获取当前总收入为:" + TotalFee);
        return TotalFee;
    }

    //7. 获取当前总退款
    public int getRefund() {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "select refund from totalfee where index1 = 0";
        int Refund = (int) totalFeeDAO.queryScalar(sql);
        System.out.println("获取当前总退款为:" + Refund);
        return Refund;
    }

    //8. 获取当前月卡总收入
    public int getMonthIncome() {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "select monthincome from totalfee where index1 = 0";
        int MonthIncome = (int) totalFeeDAO.queryScalar(sql);
        System.out.println("获取当前月卡收入为:" + MonthIncome);
        return MonthIncome;
    }

    //9. 获取当前次卡总收入
    public int getTimesIncome() {
        TotalFeeDAO totalFeeDAO = new TotalFeeDAO();
        String sql = "select timesincome from totalfee where index1 = 0";
        int TimesIncome = (int) totalFeeDAO.queryScalar(sql);
        System.out.println("获取当前当前次卡收入为:" + TimesIncome);
        return TimesIncome;
    }
}
